package sd.zhr.moodcapsule.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import sd.zhr.moodcapsule.mapper.UserMapper;
import sd.zhr.moodcapsule.pojo.UserDto;
@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        UserDto user=userMapper.findByUsername(username);
        if(user==null){
            //如果用户查不到，抛出异常
            throw  new UsernameNotFoundException("用户不存在");
        }
        return user;
    }
}
